package com.kye.express.business.customer_intro.add;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;

import com.kye.base.Logger;
import com.kye.express.R;
import com.kye.express.databinding.ItemIntroCompanyBinding;
import com.kye.model.bean.customer_intro.IntroCompyModel;

class IntroCompanyitemViewBinder extends me.drakeet.multitype.ItemViewBinder<IntroCompyModel, IntroCompanyitemViewBinder.ViewHolder> {

    private Context mContext;

    public IntroCompanyitemViewBinder(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_intro_company, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull IntroCompyModel item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private IntroCompyModel data;
        ItemIntroCompanyBinding dataBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            dataBinding = DataBindingUtil.bind(itemView);
        }


        public void bindData(IntroCompyModel item) {
            data = item;
            if (data != null) {
                dataBinding.setData(data);
                dataBinding.checkbox.setText(data.getName());
                dataBinding.checkbox.setChecked(data.isCheck());
                dataBinding.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                        data.setCheck(b);
                        Logger.d("onCheckedChanged");
                    }
                });
            }
        }
    }
}
